import QtQuick 2.7
import QtQuick.Controls 2.5

import "./widgets" as Widgets
import "./layouts" as Layouts

Rectangle {
    id: root

    property string reportId: ""
    property string reportTime: ""

    signal back()

    //////////////////////////////

    Component.onCompleted:  {
        listModel.append({"name": qsTr("檢體編號"), "result": (reportId ? reportId : qsTr("20181010-001-04"))})
        listModel.append({"name": qsTr("測試品項"), "result": qsTr("胃幽門螺旋杆菌")})
        listModel.append({"name": qsTr("測試時間"), "result": (reportTime ? reportTime : qsTr("2018/10/10 09:48:37"))})
        listModel.append({"name": qsTr("快篩批次"), "result": qsTr("A0020319Q401")})
        listModel.append({"name": qsTr("檢體種類"), "result": qsTr("糞便")})
        listModel.append({"name": qsTr("照片"), "result": qsTr("qrc:/image/img_fake_strip_001.jpg")})
        listModel.append({"name": qsTr("C 線"), "result": qsTr("+")})
        listModel.append({"name": qsTr("T 線"), "result": qsTr("+")})
        listModel.append({"name": qsTr("結果"), "result": qsTr("陽性")})
        listModel.append({"name": qsTr("品管人員"), "result": qsTr("POCTHPY001")})

    }

    /////////////////////////////////////////
    Layouts.TopLayout {
        id: toolBar
        z: 100
        width: parent.width
        height: root.height * 0.1
        title: qsTr("報告詳情")

        onClickedBack: root.back()
    }

    ///////////////////
    Item {
        width: parent.width
        height: parent.height - toolBar.height
        y: toolBar.height

        ListView {
            anchors.centerIn: parent
            width: parent.width * 0.75
            height: parent.height * 0.75
            spacing: 2
            clip: true

            model: ListModel {
                id: listModel
            }

            delegate: Rectangle {
                width: parent.width
                height: root.height * 0.06
                color: index % 2 == 0 ? "#ccc" : "#e1e1e1"

                Row {
                    width: parent.width
                    height: parent.height
                    Text {
                        width: parent.width * 0.3
                        height: parent.height
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignVCenter
                        font.pixelSize: height * 0.35
                        text: name
                    }

                    Rectangle {
                        width: 2
                        height: parent.height
                        color: "#F1F1F1"
                    }

                    Text {
                        width: parent.width * 0.7
                        height: parent.height
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignVCenter
                        font.pixelSize: height * 0.35
                        text: result
                        visible: result.indexOf("qrc:/")!==0
                    }

                    Image {
                        width: parent.width * 0.7
                        height: parent.height
                        fillMode: Image.PreserveAspectFit
                        source: result.indexOf("qrc:/")===0?result:""
                        visible: result.indexOf("qrc:/")===0
                    }
                }


            }

            ScrollBar.vertical: ScrollBar {}
        }
    }

}
